import Vue from "vue";
import VueRouter from "vue-router";

import routes from "./routes";

Vue.use(VueRouter);

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
/**
 * 路由跳转之前的钩子函数
 * @param to 将要跳转的route
 * @param from 从哪里跳转过来的
 * @next 放行
 */
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  } else if (to.matched[0].meta.title) {
    document.title = to.matched[0].meta.title;
  }
  // 允许进行跳转
  next();
})
export default router;
